<script lang="ts" setup>
	import { onLaunch, onShow, onHide } from "@dcloudio/uni-app";
	import { $system, useStorage, $http } from './utils';
	import { useUserStore, useWebConfigStore } from "@/stores";
	onLaunch((options : any) => {
		// uni.hideTabBar();
		const storeage = useStorage();
		const appid = options.query?.appid || $system.appid();

		if (!appid) {
			uni.showModal({
				content: '授权地址不正确，请重新访问',
				showCancel: false
				, success() {
					// #ifdef MP-WEIXIN
					uni.navigateBack();
					// #endif
				}
			})
		}

		const { setWebConfig, initWebConfig } = useWebConfigStore();
		initWebConfig();
		$http.get('Config/getConfig').then((res:any) => {
			setWebConfig(res.data);
		})

		const icode = options.query?.icode;
		if (icode && !storeage.get('ICODE.' + appid)) {
			storeage.set('ICODE.' + appid, icode);
		}
		const puid = options.query?.puid;
		if (puid && !storeage.get('PUID.' + appid)) {
			storeage.set('PUID.' + appid, puid);
		}
		// #ifdef MP-WEIXIN
		const scene = options.query?.scene;
		if (scene) {
			const sceneArr = decodeURIComponent(scene).split('&');
			const sceneObj : any = {};
			sceneArr.forEach((item : string) => {
				const arr = item.split('=');
				sceneObj[arr[0]] = arr[1];
			})
			if (sceneObj.puid) {
				storeage.set('PUID.' + appid, sceneObj.puid);
			}
		}
		// #endif

		console.log('App Launch')
	})
	onShow(() => {
		console.log('App Show')
	})
	onHide(() => {
		console.log('App Hide')
	})
</script>

<style lang="scss">
	view {
		outline: none;
		box-sizing: border-box;
	}

	/*每个页面公共css */
	@import "static/common.scss";

	page {
		background-color: #121213;
	}

	.bg-c {
		background-color: #121213;
	}
	
	.ellipsis-text {
	  white-space: nowrap; /* 禁止换行 */
	  overflow: hidden; /* 隐藏溢出部分 */
	  text-overflow: ellipsis; /* 显示省略号 */
	}
</style>